package com.futures.questionbank.base;

import android.app.Activity;
import android.app.Application;
import android.os.Handler;
import android.os.Process;

import com.futures.questionbank.Utils.LogUtil;
import com.raizlabs.android.dbflow.config.FlowManager;
import com.tencent.bugly.Bugly;

import java.util.ArrayList;
import java.util.List;

public class BaseApplication extends Application {

    private static BaseApplication mInstance;

    /**
     * 主线程ID
     */
    private static int mMainThreadId = -1;
    /**
     * 主线程ID
     */
    private static Thread mMainThread;

    /**
     * 主线程Handler
     */
    private static Handler mMainThreadHandler;



    private static List<Activity> records = new ArrayList<>();

    public static BaseApplication getApplication() {
        return mInstance;
    }

    /**
     * 获取主线程ID
     */
    public static int getMainThreadId() {
        return mMainThreadId;
    }

    /**
     * 获取主线程
     */
    public static Thread getMainThread() {
        return mMainThread;
    }

    /**
     * 获取主线程的handler
     */
    public static Handler getMainThreadHandler() {
        return mMainThreadHandler;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mMainThreadId = Process.myTid();
        mMainThread = Thread.currentThread();
        mMainThreadHandler = new Handler();
        mInstance = this;
        //初始化DBFLOW
        FlowManager.init(this);
        Bugly.init(getApplicationContext(), "90020eeb78", false);
        LogUtil.init();
    }



    public void addActvity(Activity activity) {
        records.add(activity);
    }

    public void removeActvity(Activity activity) {
        records.remove(activity);
    }


}
